function [SEs_Boot thetaBoot exitflagBoot] = getVarCovBootstrapCluster(Theta_0, VoteDem, VoterIdeal, CandTypeDem, CandTypeRep, DemCandIdeal, DemPartyIdeal, RepCandIdeal, RepPartyIdeal, RHS, UtilFuncParam, ChoiceProbForm, NumBootReps, options1, options2, RandomizationSeed, ClusterIndex)

rand('twister',RandomizationSeed);

thetaBoot = zeros(length(Theta_0), NumBootReps);
fvalBoot = zeros(1, NumBootReps);
exitflagBoot = zeros(1, NumBootReps);

parfor i = 1:NumBootReps

ClusterSampleIndex = unidrnd(max(ClusterIndex), [max(ClusterIndex), 1]);

RHSBootSample = []; VoteDemBootSample = []; VoterIdealBootSample = []; CandTypeDemBootSample = []; CandTypeRepBootSample = [];
DemCandIdealBootSample = []; DemPartyIdealBootSample = []; RepCandIdealBootSample = []; RepPartyIdealBootSample = []; 

%%Defining Clustered Bootstrap Sample
for j = 1:max(ClusterIndex)
    RHSBootSample = vertcat(RHSBootSample, RHS(ClusterIndex == ClusterSampleIndex(j,:),:));
    VoteDemBootSample = vertcat(VoteDemBootSample, VoteDem(ClusterIndex == ClusterSampleIndex(j,:),:));
    VoterIdealBootSample = vertcat(VoterIdealBootSample, VoterIdeal(ClusterIndex == ClusterSampleIndex(j,:),:));    
    CandTypeDemBootSample = vertcat(CandTypeDemBootSample, CandTypeDem(ClusterIndex == ClusterSampleIndex(j,:),:));
    CandTypeRepBootSample = vertcat(CandTypeRepBootSample, CandTypeRep(ClusterIndex == ClusterSampleIndex(j,:),:));
    
    DemCandIdealBootSample = vertcat(DemCandIdealBootSample, DemCandIdeal(ClusterIndex == ClusterSampleIndex(j,:),:));
    DemPartyIdealBootSample = vertcat(DemPartyIdealBootSample, DemPartyIdeal(ClusterIndex == ClusterSampleIndex(j,:),:));
    RepCandIdealBootSample = vertcat(RepCandIdealBootSample, RepCandIdeal(ClusterIndex == ClusterSampleIndex(j,:),:));
    RepPartyIdealBootSample = vertcat(RepPartyIdealBootSample, RepPartyIdeal(ClusterIndex == ClusterSampleIndex(j,:),:));
end

%%Estimating Parameters for Each Bootstrap Sample
[thetaBoot(:,i), fvalBoot(:,i), exitflagBoot(:,i)] = fminunc(@(Theta) IndivVoterObjFun(Theta, VoteDemBootSample, VoterIdealBootSample, CandTypeDemBootSample, CandTypeRepBootSample, DemCandIdealBootSample, DemPartyIdealBootSample, RepCandIdealBootSample, RepPartyIdealBootSample, RHSBootSample, UtilFuncParam, ChoiceProbForm), Theta_0, options2);

end

%%Estimating SEs from Bootstrap Replications
SEs_Boot = sqrt((1/(NumBootReps-1)).*sum((thetaBoot - repmat(mean(thetaBoot,2), 1, NumBootReps)).^2,2));